﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace WizzardTheGame
{
    class Bar
    {
        private Object2D hp;
        private Object2D exp;
        private Object2D backdrop;
        private ObjectText level;
        private Color barColor;
        private Vector2 position;
        private bool isVisible;

        #region Properties

        public Object2D EXP
        {
            get { return exp; }
            set { exp = value; }
        }

        public Object2D HP
        {
            get { return hp; }
            set { hp = value; }
        }

        public Object2D Backdrop {
            get { return backdrop; }
            set { backdrop = value; }
        }

        public ObjectText Level
        {
            get { return level; }
            set { level = value; }
        }

        public Color BarColor {
            get { return barColor; }
            set { barColor = value; }
        }

        public Vector2 Position {
            get { return position; }
            set { position = value; }
        }

        public bool IsVisible {
            get { return isVisible; }
            set { isVisible = value; }
        }

        #endregion

        public Bar()
        {
            IsVisible = false;

            Backdrop = new Object2D();
            Backdrop.LoadContent("Sprites\\BarBackdrop");
            backdrop.IsVisible = true;

            HP = new Object2D();
            HP.SetPos(85, 10);
            HP.LoadContent("Sprites\\BarHP");
            HP.IsVisible = true;

            EXP = new Object2D();
            EXP.SetPos(85, 30);
            EXP.LoadContent("Sprites\\BarEXP");
            EXP.IsVisible = true;

            Level = new ObjectText();
            Level.Position = new Vector2(25,28);
            Level.Font = GameWorld.getInstance().Content.Load<SpriteFont>("Fonts\\Bookman");
            Level.Text = "";
            Level.Color = Color.DarkGoldenrod;
            Level.AlphaValue = 200;
            Level.IsVisible = true;
        }

        public void CalcHP(int max, int current)
        {
            HP.Width = (int)(HP.Sprite.Width * Calc(max, current));
        }

        public void CalcEXP(int max, int current)
        {
            EXP.Width = (int)(EXP.Sprite.Width * Calc(max, current));
        }

        private float Calc(int max, int current)
        {
            return (float) current /(float) max;
        }

        public void Draw()
        {
            if (IsVisible)
            {
                Backdrop.Draw();
                HP.Draw();
                EXP.Draw();
                Level.Draw();
            }
        }
    }
}
